package com.singzi.javaSenior.reflect;

import lombok.SneakyThrows;

import java.lang.reflect.Method;
import java.sql.Time;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class MainTiming {
    public static void main(String[] args) {
        Timer timer = new Timer();
        Calendar now = Calendar.getInstance();
        now.set(Calendar.SECOND,now.get(Calendar.SECOND)+1);
        Date time = now.getTime();

        MyTask task = new MyTask();
        timer.scheduleAtFixedRate(task, time, 3000);

    }
}
class Worker{
    public static void hello() {
        System.out.println("Hello Java!");
    }
}
class MyTask extends TimerTask{

    @SneakyThrows
    @Override
    public void run() {
        Method hello = Class.forName("com.singzi.javaSenior.reflect.Worker").getMethod("hello");
        hello.invoke(null);
    }
}
